/**
 * 
 */
package design_pattern.command.awt.undo;

import java.awt.Color;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * @author linzq
 * 
 */
public class TheWorld extends Frame implements ActionListener {

  private Panel p;

  private LetThreeBeLandCommand btnLand;

  private LetThreeBeLightCommand btnLight;

  private ResetCommand btnReset;

  public TheWorld() {
    super("This is the world, and God says...");
    p = new Panel();
    p.setBackground(Color.black);

    this.add(p);

    btnLight = new LetThreeBeLightCommand("Let three be light.", p);

    btnLand = new LetThreeBeLandCommand("Let three be land.", p);

    btnReset = new ResetCommand("reset.", p);

    p.add(btnLand);
    p.add(btnLight);
    p.add(btnReset);

    btnLight.addActionListener(this);
    btnLand.addActionListener(this);
    btnReset.addActionListener(this);

    this.setBounds(100, 100, 400, 200);
    this.setVisible(true);

    this.addWindowListener(new WindowListener() {

      @Override
      public void windowOpened(WindowEvent e) {

      }

      @Override
      public void windowIconified(WindowEvent e) {

      }

      @Override
      public void windowDeiconified(WindowEvent e) {}

      @Override
      public void windowDeactivated(WindowEvent e) {

      }

      @Override
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }

      @Override
      public void windowClosed(WindowEvent e) {
        System.out.println("..");
      }

      @Override
      public void windowActivated(WindowEvent e) {

      }
    });

  }

  public static void main(String[] args) {
    new TheWorld();
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    Command comand = (Command) e.getSource();
    comand.execute(e);
  }

}
